require("./css/index.scss");
require("../common/common.scss");

import {
    createBtnHandler
} from './create';
import {
    editBtnHandler
} from './edit';
import {
    removeBtnHandler
} from './remove';
import {
    grid
} from '../common/grid';
import {
    editPwd, loginOut
} from '../common/settings';


$(function () {

    grid();
    window.editPwd = editPwd;
    window.loginOut = loginOut;


    let $table = $('#table').bootstrapTable({
        toolbar: '#toolbar',
        url: GLOBAL_adminListUrl,
        sidePagination: "server",
        queryParamsType: '',
        sortName: '',
        columns: [{
            checkbox: true
        }, {
            field: 'name',
            title: '用户名',
            sortable: true
        }, {
            field: 'rolename',
            title: '角色',
            sortable: true
        }, {
            field: 'mobile',
            title: '手机号',
            sortable: true
        }, {
            field: 'create_time',
            title: '添加时间',
            sortable: true
        }, {
            field: 'update_time',
            title: '最后登录',
            sortable: true
        }]
    });


    window.createBtnHandler = createBtnHandler;
    window.editBtnHandler = editBtnHandler;
    window.removeBtnHandler = removeBtnHandler;

    //多选不能编辑
    $table.on('check.bs.table', () => {
        let selectedList = $('#table').bootstrapTable('getSelections');
        if (selectedList.length > 1) {
            $('#editBtn').attr('disabled', 'disabled');
            return;
        }
        $('#editBtn').removeAttr('disabled');
    });
    $table.on('uncheck.bs.table', () => {
        let selectedList = $('#table').bootstrapTable('getSelections');
        if (selectedList.length > 1) {
            $('#editBtn').attr('disabled', 'disabled');
            return;
        }
        $('#editBtn').removeAttr('disabled');
    });
    $table.on('check-all.bs.table', (rows) => {
        $('#editBtn').attr('disabled', 'disabled');
    });
    $table.on('uncheck-all.bs.table', (rows) => {
        $('#editBtn').removeAttr('disabled');
    });


});